package learning.groovy.closure

class ClosureCalling {
	static main(args){
		def adder = { x,y -> return x+y}
		println adder(4,3) //7
		println adder.call(2,6) //8

		def slow = benchmark(10000){ (int) it / 2}
		def fast = benchmark(10000){ it.intdiv(2) }
		println slow
		println fast
		
	}

	static def benchmark(repeat,Closure worker){
		def start = System.currentTimeMillis()
		repeat.times{worker(it)}
		def stop = System.currentTimeMillis()
		return stop -start
	}
}
